<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">

  <script th:src="@{/}+'js/tool.js'"></script>
  <style type="text/css">
	.layui-form .layui-form-item{
		width:90%;
	}
	.layui-input-inline{
		width:500px!important
	}
  </style>
</head>
<body style="margin-top: 10px">
<form lay-filter="myform" id="myform" class="layui-form">
	<input type="hidden" name="id">
	<input type="hidden" name="fid" id="fid" th:value="${userId}">
  <div class="layui-form-item">
    <label class="layui-form-label">名称</label>
    <div class="layui-input-inline">
      <input type="text" name="name" id="fileName" autocomplete="off" class="layui-input">
    </div><div class="layui-form-mid layui-word-aux">可选项，不填则默认取文件名称</div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">备注说明</label>
    <div class="layui-input-inline">
      <input type="text" name="descs" id="descs" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
  	<label class="layui-form-label">上传人</label>
	<div class="layui-input-inline">
       <input type="text" name="createUserName" id="createUserName" lay-filter="createUserName" th:value="${session.me.name}" readonly="readonly" class="layui-input">
       <input type="hidden" name="createUserId" id="createUserId" th:value="${session.me.name}">
	</div>
  </div>
  <div class="layui-form-item">
	<label class="layui-form-label">上传时间</label>
	<div class="layui-input-inline">
       	<input type="text" name="createTime" id="createTime" lay-filter="createTime" readonly="readonly" th:value="${currentTime}" class="layui-input">
	</div>
  </div>
  <div class="layui-form-item">
	<label class="layui-form-label">文件</label>
	<div class="layui-input-inline" id="file" style="height:30px;border:1px solid #BEBEBE;padding-top: 8px;padding-left:10px">
       	<input type="button" value="选择文件" id="selectFile">
	</div>
  </div>
  <input type="button" class="subtn" value="上传附件" id="upload" style="display:none">
  <button id="submitBtn" class="layui-btn" style="display:none" lay-submit lay-filter="submitme">保存</button>
</form>
 <script th:inline="javascript">
/*<![CDATA[*/
var id=/*[[${id}]]*/     
/*]]>*/
</script>
<script th:inline="none">
layui.use(['form','table','upload'], function(){
	  var form = layui.form
	  ,table = layui.table
	  ,upload = layui.upload;

	layui.upload.render({
		 elem: '#selectFile'
		 ,bindAction: '#upload'
		 ,url: 'attachment/upload'
		 ,auto: false
		 ,multiple: false
		 ,accept:"file"
		// ,exts:"jpg|png|gif|bmp|jpeg|mp4|avi|flv|wmv"
		 ,data:{
			 fid: $("#fid").val(),
			 name:()=>$("#fileName").val(),
			 descs:()=>$("#descs").val(),
			 table_name:"sys_user",
			 zip_field_name:"name"
		 }
		 ,done: function(ret, index, upload) {
			 if(ret.code==0){
				 let win = getTabWin();
				 win.loadGrid("attachment-table");
				 var index = top.layer.getFrameIndex(window.name); 
				 top.layer.close(index);
			 }else{
				 layer.msg(ret.msg);
			 }
			 	
		 }
	});
	form.on('submit(submitme)', function(data){
		var values = {};
		$(":input").each(function(i,v){
			values[v.name] = v.value;
		})
		$.ajax({
			url: 'attachment/save',
			data: values,
			type:'POST',
			dataType:'JSON',
			success:function(ret){
				parent.loadGrid("attachment-table");
				layer.msg("保存成功");
				var index = parent.layer.getFrameIndex(window.name); 
				parent.layer.close(index); 
			}
		})
		return false; 
	});
	function loadData(){
		var entity = getEntityInfo(id,"attachment/getById");
		form.val("myform",entity);
		$("#file").html(entity.name+entity.ext)
	 }
	  
	 if(id){
		 loadData();
	 }
})

</script>
</body>
</html>